package cn.com.inossem.operation;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.Bundle;
import cn.com.inossem.activity.ModelCenterActivity;
import cn.com.inossem.config.WSConfig;
import cn.com.inossem.model.UploadSkillInfoBean;
import cn.com.inossem.network.NetworkConnect;

import com.foxykeep.datadroid.exception.ConnectionException;
import com.foxykeep.datadroid.exception.CustomRequestException;
import com.foxykeep.datadroid.exception.DataException;
import com.foxykeep.datadroid.requestmanager.Request;
import com.foxykeep.datadroid.service.RequestService.Operation;
import com.google.gson.Gson;

public class UploadSkillsOperation implements Operation {

	public static final String MESSAGE_OPERATION_SKILLS = "message_operation_skills";

	public static Bundle bundle;

	Context content = null;

	@Override
	public Bundle execute(Context arg0, Request request)
			throws ConnectionException, DataException, CustomRequestException {
		Gson gson = new Gson();
		UploadSkillInfoBean bean = new UploadSkillInfoBean();
		bean.setListProjectForUser(ModelCenterActivity.xuanzhongModel);
		String tojson = gson.toJson(bean).toString();
		System.out.println("UploadSkillsOperation tojson:" + tojson);

		NetworkConnect connection = new NetworkConnect(WSConfig.LOCAL_URL
				+ "userInfo/addOrUpdateUserSkill");
		connection.setPostText(tojson);
		String body = connection.execute();

		System.out.println("UploadSkillsOperation:" + body);
		bundle = new Bundle();
		try {
			JSONObject jsonObject = new JSONObject(body);
			int errorFlag = jsonObject.getInt("errorFlag");

			if (errorFlag == WSConfig.RESULT_SUCESS) {
				//Toast.makeText(arg0, "保存成功!", Toast.LENGTH_LONG).show();
			} else {
				//Toast.makeText(arg0, "保存失败!", Toast.LENGTH_LONG).show();
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return bundle;
	}
}
